package com.example.XueCuApp.View;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.XueCuApp.Base.BaseActivity;
import com.example.XueCuApp.Base.BaseConfig;
import com.example.XueCuApp.R;
import com.example.XueCuApp.Utils.SPUtil;
import com.example.XueCuApp.Utils.StringUtil;
import com.example.XueCuApp.Utils.ToastUtil;

public class SettingIPActivity extends BaseActivity {

    private EditText IpInput;
    private EditText IpInputLogin;
    private Button btSave;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public int initLayoutId() {
        return R.layout.activity_setting_ip;
    }

    @Override
    protected void initView() {
        IpInputLogin = (EditText) findViewById(R.id.et_ip_input_login);
        IpInput = (EditText) findViewById(R.id.et_ip_input);
        btSave = (Button) findViewById(R.id.bt_save);
        IpInputLogin.setText((String) SPUtil.get(SettingIPActivity.this, BaseConfig.Base_URL_STRING_LOGIN,""));
        IpInput.setText((String) SPUtil.get(SettingIPActivity.this, BaseConfig.Base_URL_STRING,""));
    }

    @Override
    protected void initData() {
        btSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断输入的是否是url
                String input = IpInput.getText().toString().trim();
//                String inputLogin = IpInputLogin.getText().toString().trim();
                if (StringUtil.isURL(input)) {
                    // 输入正确的地址，对地址进行保存
                    SPUtil.put(SettingIPActivity.this, BaseConfig.Base_URL_STRING, input);
                    ToastUtil.showToast("地址保存成功");
                } else {
                    ToastUtil.showToast("请输入正确的地址");
                    return;
                }
                finish();
            }
        });
    }
}
